<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<%@ page import="com.scalar.chiptrack.utils.ConfigManager,
                 java.util.ArrayList"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>
<chiptrack:checkLogon sourcePage="/financeReport.do?action=InventoryCost" />

<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>
<%
    String baseProductId = ""+request.getParameter("baseproductID");
    if( baseProductId == null || ( baseProductId != null && baseProductId.trim().length() == 0 ) )
    {
        baseProductId = "0";
    }
%>
<HTML>
    <HEAD>
    <SCRIPT language="JavaScript" src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></SCRIPT>
    <SCRIPT language="JavaScript" src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></SCRIPT>
    <script language="JavaScript">
    var dateElement = "";
    function openCalendar(dateValue)
    {
        dateElement = dateValue;
        newWindow = window.open('<%=chipTracContext%>/jsp/includes/calendar.html','optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=no,width=180,height=440,resizable=no');
        newWindow.moveTo(550,180);
        newWindow.focus();
    }
    function assignDate(passedValue)
    {
        dateElement.value=passedValue;
        window.focus();
    }
    function selectBaseProduct()
    {
        var productId = document.inventoryCost.products.value;

        if( productId == '' || productId == '0')
        {
            document.inventoryCost.action="<%=chipTracContext%>/financeReport.do?action=inventoryCost";
            document.inventoryCost.submit();
            return;
        }
        document.inventoryCost.action='<%=chipTracContext%>/financeReport.do?action=inventoryCost&baseproductID='+productId;
        document.inventoryCost.submit();
    }
    function submitForm()
    {
        var form = document.inventoryCost;
        var d = new Date();
        var day = d.getDate();
        var month = d.getMonth()+1;
        var year = d.getFullYear();
        var hour = d.getHours();
        var min = d.getMinutes();
        var sec = d.getSeconds();
        var fromDate = form.fromDate.value.trim();
        var toDate   = form.toDate.value.trim();

        var defaultPrompt = day+"/"+month+"/"+year+":"+hour+":"+min+":"+sec;
        if ( validateFromAndToDates() )
        {
            form.prompt0.value = '0';
            form.prompt1.value = document.inventoryCost.products.options[document.inventoryCost.products.selectedIndex].value;
            form.prompt2.value = document.inventoryCost.partNumber.options[document.inventoryCost.partNumber.selectedIndex].value;
            form.prompt3.value = '0';
            if ( fromDate.length > 0 )
            {
                form.prompt4.value = fromDate;
            }
            else
            {
                form.prompt4.value = '0';
            }
            if ( toDate.length > 0 )
            {
                form.prompt5.value = toDate;
            }
            else
            {
                form.prompt5.value = '0';
            }
            form.prompt6.value = '0';
            form.prompt7.value = defaultPrompt;

            document.inventoryCost.action="<%=chipTracContext%>/jsp/report.jsp?nameReport=Finance/New_Cost/Standard_Inventory_Cost_Report.rpt";
            document.inventoryCost.submit();
        }
    }
    function validateFromAndToDates()
    {
        var form = document.inventoryCost;
        errMsg = '';
        var errors = '';
        var pa	= document.getElementById("errors")

        if(chkDate(form.fromDate.value,'From Date','N') == false)
        {
            errors = errors + errMsg;
            form.fromDate.focus();
        }
        if(chkDate(form.toDate.value,'To Date','N') == false)
        {
            errors = errors + errMsg;
            form.toDate.focus();
        }

        if(form.fromDate.value!='' && form.toDate.value!='' && errors == '')
        {
            if (!validateDateOut(formatDateAsMMDDYYYY(form.fromDate.value),formatDateAsMMDDYYYY(form.toDate.value)))
            {
                errors = errors + "<li>To Date cannot be less than From Date</li>";
                form.toDate.focus();
            }
        }
        if ( errors != '' )
        {
            pa.innerHTML = errors;
            return false;
        }
        return true;
    }
    </script>

    <TITLE>Scalarsoft - ChipTrac</TITLE>
    <META http-equiv=Content-Type content="text/html; charset=windows-1252">
    <LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type="text/css" rel=stylesheet>

    <META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
    <BODY bgColor="#ffffff" leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">
    <form name="inventoryCost" method="post" onSubmit="" >
        <input type="hidden" name="prompt0">
        <input type="hidden" name="prompt1">
        <input type="hidden" name="prompt2">
        <input type="hidden" name="prompt3">
        <input type="hidden" name="prompt4">
        <input type="hidden" name="prompt5">
        <input type="hidden" name="prompt6">
        <input type="hidden" name="prompt7">
        <input type="hidden" name="prompt8">
        <!-- Top Header Start-->
        <%@ include file="/jsp/includes/header.jsp" %>
        <!-- Top Header End-->
        <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
          <TBODY>
          <TR>
            <td width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>
                <!-- Side Navigation start -->
                <%@ include file="/jsp/finance/finance_cost_reports_menu.jsp" %>
                <!-- end of the side navigations -->
            <TD bgcolor="#ffffff">
            <IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
            <TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
            <TD valign="top" width="100%">
            <BR>
            <!-- from here your body starts -->
            <center><span class="NArialW">Detail Cost Report</span></center>
            <img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20 />
            <table border="0" width="90%" align=right>
                <tr><td colspan='5' class="NArialL"><chiptrack:errors styleClass="NArialL"  /></td></tr>
                <tr><td colspan='5' class="NArialL"><chiptrack:info styleClass="NArialL"  /></td></tr>
                <tr>
                    <td colspan='4' align="left" class='NArialL'>
                        <b><font face="Verdana" size="-5" align="center" color="#ff0000" id="errors"></font></b>
                    </td>
                </tr>
                <tr>
                    <td colspan='4'>&nbsp;</td>
                    <td align="left">
                        <FONT class="NArialL"><B><a href="<%=chipTracContext%>/financeReport.do?action=updateCostTable" title="Click to update inventory costs" onMouseOver="window.status='Click to update inventory costs';return true"onmouseout="window.status='';return true">Update inventory costs</a></B></FONT>
                    </td>
                </tr>
                <TR><TD colspan='5'>&nbsp;</td></tr>
                <TR>
                    <TD width="15%" class=NArialL>Base Product:</TD>
                    <TD width="15%" class=NArialL>
                        <select size="1" name="products" class="txfield" onchange="selectBaseProduct()">
                            <option value="0">All Base Products</option>
                            <logic:present name="baseProductsList">
                            <logic:iterate id="baseProduct" name="baseProductsList" type="org.apache.struts.util.LabelValueBean">
                            <% if ( baseProductId.equalsIgnoreCase( baseProduct.getValue() ) )
                            {
                            %>
                                <option value="<bean:write name="baseProduct" property="value"/>" selected >
                            <%
                            }else{
                            %>
                                <option value="<bean:write name="baseProduct" property="value"/>" >
                            <%
                            }
                            %>
                            <bean:write name="baseProduct" property="label"/>
                            </option>
                            </logic:iterate>
                            </logic:present>
                        </select>
                    </TD>
                    <TD width="5%">&nbsp;</TD>
                    <TD width="10%" class=NArialL>Products:</TD>
                    <TD width="30%" class=NArialL>
                        <select size="1" name="partNumber" class="txfield" >
                            <option value="0">All Products</option>
                            <logic:present name="mktgPartNumberdetailList">
                            <logic:iterate id="mktgPartNumberdetailList" name="mktgPartNumberdetailList">
                                <option value = <bean:write name="mktgPartNumberdetailList" property="value"/>>
                                    <bean:write name="mktgPartNumberdetailList" property="label"/>
                                </option>
                            </logic:iterate>
                            </logic:present>
                        </select>
                    </TD>
                </TR>
                <tr><td colspan="5"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
                <TR>
                    <TD WIDTH="15%" CLASS="NARIALL" Valign="center">From Date</TD>
                    <TD WIDTH="20%" CLASS="NARIALL" Valign="center">
                        <input type="text" name="fromDate" size="12" class="txfield"/>&nbsp
                        <A href="javascript:openCalendar(document.inventoryCost.fromDate)">
                        <IMG src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=20 width=20 border="0" onmouseover="window.status='Click to Select Date';return true" onmouseout="window.status='';return true"></A>
                    </TD>

                    <TD WIDTH="10%">&nbsp;</TD>

                    <TD WIDTH="13%" CLASS="NARIALL" align="center">To Date</TD>
                    <TD WIDTH="20%" CLASS="NARIALL" align="center">
                        <input type="text" name="toDate" size="12" class="txfield"/>&nbsp
                        <A href="javascript:openCalendar(document.inventoryCost.toDate)">
                        <IMG src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=20 width=20 border="0" onmouseover="window.status='Click to Select Date';return true" onmouseout="window.status='';return true"></A>
                    </TD>

                    <TD WIDTH="10%">&nbsp;</TD>
                </TR>
                <tr><td colspan="5"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
                <tr><td colspan="5"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20></td></tr>
                <tr>
                    <td colspan="5" align=center>
                        <a href="javascript:submitForm();"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/submit.gif" width="53" height="17" onmouseover="window.status='Click to Generate Inventory Cost Report';return true" onmouseout="window.status='';return true" title="Click here to Generate Inventory Cost Report"/></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <a href="javascript:document.inventoryCost.reset();"><img src="<%=chipTracContext%>/jsp/includes/images/reset.gif" border='0' onmouseover="window.status='Click to Reset';return true" onmouseout="window.status='';return true"title="Click here to Reset"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    </td>
                </tr>
            </table>
            <!-- till here -->
            <BR><BR> <BR>
            </TD>
            <TD bgcolor="#ffffff"></TD>
        </TR>
    </TABLE>
        <!-- Footer starts here -->
        <%@ include file="/jsp/includes/footer.jsp" %>
        <!-- footer end here -->
      </form>
    </BODY>
</HTML>
